/*
Author: Ryan Westfall
Class Name: Block
Functionality: this will be the object that is will represent a block in the game
Version: 0.0.4
Date written: November 15, 2011
Date tested:
Todo: 
*/

package disease;

public class Block {
    int xCoord;
    int yCoord;
    int percentOfInfection;  //can only be 0 - 100
    String blockName;
    int humanPopulation;
    int totalHumanPopulation; //the original value
    int zombiePopulation;
    // black is 0 0 0 0
    // red,green,blue,alpha relate to the color of the blocks 
    int red = 0;
    int green = 0;
    int blue = 0;
    int alpha = 0;//equal to the percentage of population left
    int infectionChance; //should be a infection priority  to rank the places where the outbreak should occure.
    double quarentined = 0; //<--the quarentined block will go down when zombie attack
    boolean inQueue = true;
    double distance = 0;
     
     
    public Block(){
    //default constructor
    xCoord = 0;
    yCoord = 0;
    percentOfInfection = 0;  //can only be 0 - 100
    blockName = "default";
    humanPopulation = 0;
    zombiePopulation = 0;
    totalHumanPopulation = 0;
    infectionChance = 0;
    distance = 0;
    }
    
    public Block(int xValue, int yValue, int humanPop, int totHumanPop, String location, int xLoc, int yLoc){
	    //overloaded constructor
	    xCoord = xValue;
	    yCoord = yValue;
	    percentOfInfection = 0;  //can only be 0 - 100
	    blockName = location;
	    humanPopulation = humanPop;
	    totalHumanPopulation = totHumanPop;
	    zombiePopulation = 0;
	    setPercentLeft(((humanPopulation)*100)/totalHumanPopulation);//100%
	    infectionChance = totalHumanPopulation/100; //this is the percent chance of a zombie infection outbreak happeing here
	    distance = Math.abs(((xCoord-xLoc)^2+(yCoord-yLoc)^2)^(1/2));
    }
   
    public void incrememntInfectionChance(int value){
    	infectionChance += value;
    }
    
    public void convertHumanToZombie(int number){
	    if(humanPopulation > 0){
	    	//System.out.println("Converting " + number + " to zombie");
	    	if(humanPopulation - number < 0){
	    		humanPopulation = 0;
	    		zombiePopulation += number;
	    	}else{
	    		humanPopulation = humanPopulation - number;
	    		zombiePopulation += number;
	    	}
	        setPercentLeft(((humanPopulation)*100)/totalHumanPopulation);
	    }
    }
   
    public void killHuman(int number){
        if(humanPopulation - number > 0){
            humanPopulation -= number;
            setPercentLeft(((humanPopulation)*100)/totalHumanPopulation);
        }else{
        	humanPopulation = 0;
        	setPercentLeft(((humanPopulation)*100)/totalHumanPopulation);
        }
    }
    
    public void killZombie(int number){
    	//System.out.println("killing " + number + " zombies");
    	if(zombiePopulation-number > 0){
    		zombiePopulation = zombiePopulation - number;
    	}else{
    		zombiePopulation = 0;
    	}
    }
    
    public void zombieAttackQuarentine(){
    	if(quarentined - 0.01 > 0){
    		quarentined = quarentined - 0.01;
    	}else{
    		quarentined = 0;
    	}
    }
     
    public void deleteFromQueue(){
    	inQueue = false;
    }
    
    private void setPercentLeft(int percentage ){
        percentOfInfection = 100 - percentage;
        setAlpha(100-percentage);
    }
   
    private void setAlpha(int percentage){
    	//sets the transparency
    	if(255*percentage/100 <= 255){
    		alpha = 255*percentage/100;
    	}else{
    		alpha = 255;
    	}
    }
    
    public void quarentineBlock(){
    	quarentined = 1.0;
    }
    
    public int getXCoord(){
    //return xCoord
    	return xCoord;
    }
     
    public int getYCoord(){
    //return yCoord
    	return yCoord;
    }
     
    public int getHumanPopulation(){
    //returns number of population remaining
    	return humanPopulation;
    }
     
    public int getTotalPopulation(){
    	return totalHumanPopulation;
    }
    
    public int getZombiePopulation(){
    //returns number of zombie population
    return zombiePopulation;
    }
    
    public int getInfectionChance(){
    	return infectionChance;
    }
 
    public int getRed(){return red;}
    
    public int getGreen(){return green;}
    
    public int getBlue(){return blue;}
    
    public int getAlpha(){return alpha;}
   
    public double getQuarentined(){
    	return quarentined;
    }
    
    public boolean inQueue(){
    	return inQueue;
    }
    
    public double getDistance(){
    	return distance;
    }
    
}